<cftimer label="Fusecache Prefuseaction Plugin - Complete - #variables.myFusebox.thisCircuit#.#variables.myFusebox.thisFuseaction#">
	<cfif IsDefined("application.oFusecacheFactory")>
	
		<!--- Build a complete fuseaction string using the ThisCircuit method.  We're doing this because
		we want to be looking at the actual, currently-running fuse, not just the master fuse that was
		request in the URL --->
		<cfset variables.sThisFuseaction = variables.myFusebox.thisCircuit & "." & variables.myFusebox.thisFuseaction />
		
		<!--- Ask the factory for a Fuseacache Request Manager object, but only once per request --->
		<cfif NOT IsDefined("variables.oFusecacheRequestManager")>
			<cfset variables.oFusecacheRequestManager = application.oFusecacheFactory.getRequestManager() />
		</cfif>
		
		<!--- Ask the factory for FusecacheItem Object for this fuseaction and pass it to the Request Manager to store --->
		<cfset variables.oFusecacheRequestManager.enterFuse(application.oFusecacheFactory.getFusecacheItem(variables.sThisFuseaction)) />
		
		<!--- Load a Fusecache item to represent the active fuseaction --->
		<cfset variables.oFusecacheItem = variables.oFusecacheRequestManager.getObjectAtDepth() />
		
		<!--- Check to see if the fuseaction is found in the config file --->
		<cfif (variables.oFusecacheItem.getFoundInSettings())>
			
			<!--- The fuseaction is in the settings file --->
			<!--- Look to see what type of item this is.  In the prefuseaction section we only deal
			with "complete-simple".  This is because partial content or content with conditionals can
			only accurately be dealt with once we've entered the fuseaction --->
			<cfswitch expression="#variables.oFuseCacheItem.getType()#">
				
				<cfcase value="complete-simple">
					<!--- Retrieve data from the cache service --->
					<cftimer label="Fusecache Prefuseaction Plugin - Retrieve Cache Data - Complete Simple - #variables.sThisFuseaction#">
						<cfset variables.oFusecacheItem.retrieveCacheData() />
					</cftimer>
				</cfcase>
				
				<cfcase value="complete-conditional|complete-variable" delimiters="|">
					<cftimer label="Fusecache Prefuseaction Plugin - Complete Conditional/Variable - Test and Load - #variables.sThisFuseaction#" type="debug">
						<!--- Confirm that there are conditions present --->
						<cfif (variables.oFusecacheItem.hasConditions() OR variables.oFusecacheItem.hasVariables())>
						
							<!--- Return a list of the necssary variables scopes based on the conditions --->
							<cfset variables.lsNeededScopes = variables.oFusecacheItem.getScopesFromConditionsOrVariables() />
							
							<!--- Loop through and collect only the necessary scopes --->
							<cfset variables.stScopes = StructNew() />
							<cfloop from="1" to="#ListLen(variables.lsNeededScopes)#" index="i">
								<cfif (ListGetAt(variables.lsNeededScopes,1) neq "Session") OR (application.getApplicationSettings().sessionManagement)>
									<cfset "variables.stScopes.#ListGetAt(variables.lsNeededScopes,1)#" = Evaluate(ListGetAt(variables.lsNeededScopes,1)) />
								</cfif>
							</cfloop>
							
							<!--- We can now pass in the need variable scopes for testing --->
							<cfset variables.oFusecacheItem.testConditionsOrVariables(variables.stScopes) />
							
						</cfif>
					</cftimer>
				</cfcase>
			
			</cfswitch>
			
			<!--- Look to see if the cache service returned any data --->
			<cfif (variables.oFusecacheItem.getFoundInCache())>
		
				<!--- We have cached data. --->
				<!--- Set myFusebox variable if it exists (it may not because it's a change to the core files!) --->
				<cfif (IsDefined("variables.myFusebox.fusecache.blnThisFuseactionCached"))>
					<cfset variables.myFusebox.fusecache.blnThisFuseactionCached = true />
				<cfelse>
					<cfif (application.oFusecacheFactory.getForceFuseboxCompletion())>
						<cfthrow type="fusecache.fuseboxCompletionUnavailable" message="In your settings XML you have set 'forceFuseboxCompletion' to true.  This feature required modifications to the Fusebox core itself.  The system was unable to find the appropriate modifications and has failed as a result." />
					</cfif>
				</cfif>
		
		
				<!--- Check to see if we're supposed to use a custom output fuseaction --->
				<!--- If we are, make sure the fuseaction we're looking at right now isn't the output fuseaction (nastly loop) --->
				<cfif (application.oFusecacheFactory.getUseOutputFuse() AND variables.sThisFuseAction NEQ application.oFusecacheFactory.getOutputFuse())>
					<!--- We're clear, so dump the cached data into the custom output variable, run the custom fuseaction, and abort of the Fusebox --->
					<cfset "#application.oFusecacheFactory.getOutputVariableName()#" = variables.oFusecacheItem.getCacheData() />
					<cfset variables.myFusebox.do(action="#application.oFusecacheFactory.getOutputFuse()#") />
					<cfif (NOT IsDefined("variables.myFusebox.fusecache.blnThisFuseactionCached"))>
						<cfabort>
					</cfif>
				<cfelse>
					<!--- No special fuseaction to run, just output the cached data in the simplest possible form and kill the Fusebox --->
					<cfoutput>#variables.oFusecacheItem.getCacheData()#</cfoutput>
					<cfif (NOT IsDefined("variables.myFusebox.fusecache.blnThisFuseactionCached"))>
						<cfabort>
					</cfif>
				</cfif>
			<cfelse>
				<!--- Set myFusebox variable if it exists (it may not because it's a change to the core files!) --->
				<cfif (IsDefined("variables.myFusebox.fusecache.blnThisFuseactionCached"))>
					<cfset variables.myFusebox.fusecache.blnThisFuseactionCached = false />
				</cfif>
			</cfif>
		
		</cfif>
		
	</cfif>
</cftimer>